package com.car.controller;

import com.car.entity.Kind;
import com.car.service.IKindService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class KindController {
    @Autowired
    @Qualifier("kindService")
    private IKindService kindService;
    //添加商品的kind查询
    @RequestMapping("/findKind")
    public String findKind(Model model){
        List<Kind> kind = kindService.findKind();
        model.addAttribute("kind",kind);
        return "add_Goods.jsp";
    }

    //商品分类管理的查询
    @RequestMapping("/findKind1")
    public String findKind1(Model model){
        List<Kind> kind = kindService.findKind();
        model.addAttribute("kind",kind);
        return "goods_CLassify.jsp";
    }
    //增加kind
    @RequestMapping("/addKind")
    public String addKind(Kind kind){
        kindService.addKind(kind);
        return "redirect:findKind1";
    }
    //删除kind
    @RequestMapping("/deleteKind")
    public String deleteKind(int kid){
        kindService.deleteKind(kid);
        return "redirect:findKind1";
    }
    //通过id查询kind
    @RequestMapping("/findKindById")
    public String findKindById(int kid,Model model){
        Kind list = kindService.findKindById(kid);
        model.addAttribute("list",list);
        return "edit_Classify.jsp";
    }

    //修改kind
    @RequestMapping("/updateKind")
    public String updateKind(Kind kind){
        kindService.updateKind(kind);
        return "redirect:/findKind1";
    }
}
